package com.ebupt.migu.music.propagate.service.impl;

import com.ebupt.migu.music.common.entity.Page;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.propagate.mapper.PropagateEffectMapper;
import com.ebupt.migu.music.propagate.service.PropagateEffectSerivce;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class PropagateEffectSerivceImpl  implements PropagateEffectSerivce {

    @Resource
    private PropagateEffectMapper propagateEffectMapper;
    @Override
    public ResultObject queryList(Map<String, Object> params) {
        ResultObject res = new ResultObject();
        List<Map<String, Object>> datas = new ArrayList<>();
        Integer total;
        total = propagateEffectMapper.queryEffectRecordsCount(params);
        // ${pageStart} , ${rows}
        int pageStart = Integer.parseInt(params.get("pageStart").toString());
        int rows = Integer.parseInt(params.get("rows").toString());
        params.put("pageStart", (pageStart - 1) * rows);
        params.put("rows", pageStart * rows);
        datas = propagateEffectMapper.queryEffectRecords(params);
        // 分页
        Page<Map<String, Object>> page = new Page<>();
        page.setTotal(total);
        page.setData(datas);
        res.setMsg("查询列表成功");
        res.setData(page);
        return res;
    }

    @Override
    public List<Map<String, Object>> export(Map<String, Object> params) {
        int pageStart = Integer.parseInt(params.get("pageStart").toString());
        int rows = Integer.parseInt(params.get("rows").toString());
        params.put("pageStart", (pageStart - 1) * rows);
        params.put("rows", pageStart * rows);
        return propagateEffectMapper.queryEffectRecords(params);
    }
}